package org.bdddemo.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.bdddemo.model.Vehicule;
import org.bdddemo.model.VehiculeRepository;
import org.springframework.stereotype.Component;

@Component
public class VehiculeRepositoryImpl implements VehiculeRepository {

	@PersistenceContext
	EntityManager entitymanager;
	public Vehicule createVehicule(Vehicule v) {

		
		Query query = entitymanager
				.createNamedQuery("insert into Stock(stock_code, stock_name)"
						+ "select stock_code, stock_name from backup_stock");
		int result = query.executeUpdate();
		if(result!=0)
		return v;
		else return null;
	}

}
